#include "stdafx.h"
#include "QConfDraw.h"
#include "QDraw.h"
#include "QView.h"

BEGIN_EVENT_TABLE(QConfDraw, wxPanel)
END_EVENT_TABLE()

QConfDraw::QConfDraw(wxWindow *parent)
	: wxPanel(parent)
{
	// Create the panel layout.
	wxBoxSizer *panelSizer = new wxBoxSizer(wxVERTICAL);

	wxFlexGridSizer *gridSizer = new wxFlexGridSizer(2, 4, 2);
	panelSizer->Add(gridSizer, 0, wxEXPAND|wxALL, 5);

	// Wireframe 2D
	wxStaticText *label = new wxStaticText(this, wxID_ANY, _("2D Views (Wireframe)"));
	wire2D = new wxChoice(this, wxID_ANY);
	gridSizer->Add(label, 0, wxALIGN_CENTER_VERTICAL);
	gridSizer->Add(wire2D);

	// Wireframe 3D
	label = new wxStaticText(this, wxID_ANY, _("3D Views (Wireframe)"));
	wire3D = new wxChoice(this, wxID_ANY);
	gridSizer->Add(label, 0, wxALIGN_CENTER_VERTICAL);
	gridSizer->Add(wire3D);

	// Solid 3D
	label = new wxStaticText(this, wxID_ANY, _("3D Views (Solid)"));
	solid3D = new wxChoice(this, wxID_ANY);
	gridSizer->Add(label, 0, wxALIGN_CENTER_VERTICAL);
	gridSizer->Add(solid3D);

	// Textured 3D
	label = new wxStaticText(this, wxID_ANY, _("3D Views (Textured)"));
	textured3D = new wxChoice(this, wxID_ANY);
	gridSizer->Add(label, 0, wxALIGN_CENTER_VERTICAL);
	gridSizer->Add(textured3D);

	// Set the sizer.
	SetSizer(panelSizer);
	panelSizer->Fit(this);

	// Load the config data.
	LoadData();
}

QConfDraw::~QConfDraw()
{
}

void QConfDraw::ApplyChanges()
{
	QView::draw2dWire = wire2D->GetStringSelection();
	QView::draw3dWire = wire3D->GetStringSelection();
	QView::draw3dSolid = solid3D->GetStringSelection();
	QView::draw3dTex = textured3D->GetStringSelection();

	QView::RefreshAll();
}

void QConfDraw::LoadData()
{
	// Build the choices and select the current driver.
	int numdrivers = QDraw::GetDriverCount();
	for(int i = 0; i < numdrivers; ++i)
	{
		const wxString &driverName = QDraw::GetDriverName(i);

		// Add the driver.
		wire2D->Append(driverName);
		wire3D->Append(driverName);
		solid3D->Append(driverName);
		textured3D->Append(driverName);

		// Select the current.
		if(QView::draw2dWire.CmpNoCase(driverName) == 0)
			wire2D->SetSelection(i);
		if(QView::draw3dWire.CmpNoCase(driverName) == 0)
			wire3D->SetSelection(i);
		if(QView::draw3dSolid.CmpNoCase(driverName) == 0)
			solid3D->SetSelection(i);
		if(QView::draw3dTex.CmpNoCase(driverName) == 0)
			textured3D->SetSelection(i);
	}
}
